﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CCWin;
namespace weiqijiance
{
    public partial class gwpz : CCSkinMain
    {
        public gwpz()
        {
            InitializeComponent();
        }

        private void gwpz_Load(object sender, EventArgs e)
        {
            string[] ssb = { "车速", "地沟", "灯光", "侧滑", "轮重", "制动", "动力性", "经济性", "悬架", "平板","外廓尺寸","整备质量" };
            for (int i = 0; i < ssb.Length; i++)
            {
                ListViewItem li = new ListViewItem();
                li.Text = ssb[i];
                listView1.Items.Add(li);
            }

            iniclass objini = new iniclass();
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\工位配置.ini";
            string path1 = string.Format(@"{0}", path);
            objini.Ini(path1);

            txtdp1.Text = objini.ReadValue("工位1配置", "灯牌").Trim();
            txtdp2.Text = objini.ReadValue("工位2配置", "灯牌").Trim();
            txtdp3.Text = objini.ReadValue("工位3配置", "灯牌").Trim();
            txtdp4.Text = objini.ReadValue("工位4配置", "灯牌").Trim();
            txtdp5.Text = objini.ReadValue("工位5配置", "灯牌").Trim();
            txtdp6.Text = objini.ReadValue("工位6配置", "灯牌").Trim();


            LED_company_1.Text = objini.ReadValue("工位1配置", "灯牌厂家").Trim();
            LED_company_2.Text = objini.ReadValue("工位2配置", "灯牌厂家").Trim();
            LED_company_3.Text = objini.ReadValue("工位3配置", "灯牌厂家").Trim();
            LED_company_4.Text = objini.ReadValue("工位4配置", "灯牌厂家").Trim();
            LED_company_5.Text = objini.ReadValue("工位5配置", "灯牌厂家").Trim();
            LED_company_6.Text = objini.ReadValue("工位6配置", "灯牌厂家").Trim();

            cbbph1.Text = objini.ReadValue("工位1配置", "屏号").Trim();
            cbbph2.Text = objini.ReadValue("工位2配置", "屏号").Trim();
            cbbph3.Text = objini.ReadValue("工位3配置", "屏号").Trim();
            cbbph4.Text = objini.ReadValue("工位4配置", "屏号").Trim();
            cbbph5.Text = objini.ReadValue("工位5配置", "屏号").Trim();
            cbbph6.Text = objini.ReadValue("工位6配置", "屏号").Trim();
            cbbph1.Text = cbbph1.Text.Length < 1 ? "1" : cbbph1.Text;
            cbbph2.Text = cbbph2.Text.Length < 1 ? "1" : cbbph2.Text;
            cbbph3.Text = cbbph3.Text.Length < 1 ? "1" : cbbph3.Text;
            cbbph4.Text = cbbph4.Text.Length < 1 ? "1" : cbbph4.Text;
            cbbph5.Text = cbbph5.Text.Length < 1 ? "1" : cbbph5.Text;
            cbbph6.Text = cbbph6.Text.Length < 1 ? "1" : cbbph6.Text;

            textBox_name1.Text = objini.ReadValue("工位1配置", "工位名称").Trim();
            textBox_name2.Text = objini.ReadValue("工位2配置", "工位名称").Trim();
            textBox_name3.Text = objini.ReadValue("工位3配置", "工位名称").Trim();
            textBox_name4.Text = objini.ReadValue("工位4配置", "工位名称").Trim();
            textBox_name5.Text = objini.ReadValue("工位5配置", "工位名称").Trim();
            textBox_name6.Text = objini.ReadValue("工位6配置", "工位名称").Trim();


            checkBox1.Checked = objini.ReadValue("工位1配置", "启用") == "1" ? true : false;
            checkBox2.Checked = objini.ReadValue("工位2配置", "启用") == "1" ? true : false;
            checkBox3.Checked = objini.ReadValue("工位3配置", "启用") == "1" ? true : false;
            checkBox4.Checked = objini.ReadValue("工位4配置", "启用") == "1" ? true : false;
            checkBox5.Checked = objini.ReadValue("工位5配置", "启用") == "1" ? true : false;
            checkBox6.Checked = objini.ReadValue("工位6配置", "启用") == "1" ? true : false;

            textBox1.Text = objini.ReadValue("工位配置", "通讯").Trim();
            //textBox2.Text = objini.ReadValue("工位2配置", "通讯").Trim();
            //textBox3.Text = objini.ReadValue("工位3配置", "通讯").Trim();
            //textBox4.Text = objini.ReadValue("工位4配置", "通讯").Trim();
            //textBox5.Text = objini.ReadValue("工位5配置", "通讯").Trim();
            //textBox6.Text = objini.ReadValue("工位6配置", "通讯").Trim();
            getsbpz(objini, "工位1配置", listView2);
            getsbpz(objini, "工位2配置", listView3);
            getsbpz(objini, "工位3配置", listView4);
            getsbpz(objini, "工位4配置", listView5);
            getsbpz(objini, "工位5配置", listView6);
            getsbpz(objini, "工位6配置", listView7);

            txtwqdp.Text = objini.ReadValue("尾气配置", "灯牌").Trim();
            LED_company_wq.Text = objini.ReadValue("尾气配置", "灯牌厂家").Trim();

            
          //lzj191114  txtsqqzr.Text = objini.ReadValue("工位配置", "授权签字人");
            
            //comboBox1.Text = objini.ReadValue("工位配置", "联网平台");
            //comboBox2.Text = objini.ReadValue("工位配置", "是否联网");
            comboBox3.Text = objini.ReadValue("工位配置", "检测线");
            textBox2.Text = objini.ReadValue("工位配置", "抓拍IP地址");
            textBox3.Text = objini.ReadValue("工位配置", "抓拍端口");
            comboBox4.Text = objini.ReadValue("工位配置", "检测时间是否达标");


            chedongtai.Checked = objini.ReadValue("工位配置", "动态使用工位机控制") == "是" ? true : false;
            cheddg.Checked = objini.ReadValue("工位配置", "启用多地沟") == "是" ? true : false;
            textBox4.Text = objini.ReadValue("工位配置", "联网平台");
            //if (comboBox1.Text.Contains("睿擎"))
            //{
            //    textBox2.Visible = true;
            //    textBox3.Visible = true;
            //    label10.Visible = true;
            //    label9.Visible = true;
            //}
            //else
            //{
            //    textBox2.Visible = false;
            //    textBox3.Visible = false;
            //    label10.Visible = false;
            //    label9.Visible = false;
            //}

           
        }

        private void button1_Click(object sender, EventArgs e)
        {
           
           
        }

        public void sbpz(iniclass objini, string section, ListView lv)
        {
            int icount = 0;
            foreach (ListViewItem li in lv.Items)
            {
                objini.Writue(section, "设备" + (icount + 1).ToString(), li.SubItems[0].Text.Trim());
                icount++;
            }
            objini.Writue(section, "设备数", icount.ToString());
        }
        public void getsbpz(iniclass objini, string section, ListView lv)
        {
            int icount = 0;

            string scount = objini.ReadValue(section, "设备数");
            int.TryParse(scount, out icount);
            for (int i = 0; i < icount; i++)
            {
                string ssbs = objini.ReadValue(section, "设备" + (i + 1).ToString()).Trim();
                if (!string.IsNullOrWhiteSpace(ssbs))
                {
                    ListViewItem li = new ListViewItem();
                    li.Text = ssbs;
                    lv.Items.Add(li);
                    foreach (ListViewItem liex in listView1.Items)
                    {
                        if (liex.Text == ssbs)
                        {
                            listView1.Items.Remove(liex);
                            break;
                        }
                    }
                }
            }
        }

        private void 增加到工位1ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            addshebei(listView1, listView2);
        }

        private void 增加到工位2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            addshebei(listView1, listView3);

        }

        private void 增加到工位3ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            addshebei(listView1, listView4);
        }

        private void 增加到工位4ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            addshebei(listView1, listView5);
        }

        private void 增加到工位5ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            addshebei(listView1, listView6);
        }

        private void 增加到工位6ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            addshebei(listView1, listView7);
        }
        public void addshebei(ListView lv, ListView lv2)
        {
            foreach (ListViewItem li in lv.SelectedItems)
            {
                foreach (ListViewItem li2 in lv2.Items)
                {
                    if (li2.SubItems[0].Text == li.SubItems[0].Text)
                    {
                        MessageBox.Show("已有该设备!");
                        return;
                    }
                }
                ListViewItem liex = new ListViewItem();
                liex.Text = li.Text;
                lv2.Items.Add(liex);
                lv.Items.Remove(li);
                break;
            }
        }

        private void 向上ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem li in listviewselect.SelectedItems)
            {
                int index = li.Index;
                if (index < 1)
                {
                    MessageBox.Show("已经在最上面");
                    return;
                }
                listviewselect.Items.RemoveAt(index);
                listviewselect.Items.Insert(index - 1, li);

            }
        }

        private void 向下ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem li in listviewselect.SelectedItems)
            {
                int index = li.Index;
                if (index >= listviewselect.Items.Count - 1)
                {
                    MessageBox.Show("已经在最下面");
                    return;
                }
                listviewselect.Items.RemoveAt(index);
                listviewselect.Items.Insert(index + 1, li);

            }
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem li in listviewselect.SelectedItems)
            {
                listviewselect.Items.Remove(li);
                listView1.Items.Add(li.Text);
            }
        }

        private void 清空ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem li in listviewselect.Items)
            {
                listView1.Items.Add(li.Text);
            }
            listviewselect.Items.Clear();
        }

        ListView listviewselect;

        private void contextMenuStrip2_Opening_1(object sender, CancelEventArgs e)
        {

            listviewselect = (ListView)(sender as ContextMenuStrip).SourceControl;
        }

        private void skinBut_chaxun_Click(object sender, EventArgs e)
        {
            iniclass objini = new iniclass();
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\工位配置.ini";
            string path1 = string.Format(@"{0}", path);
            objini.Ini(path1);

            objini.Writue("工位1配置", "灯牌", txtdp1.Text.Trim());
            objini.Writue("工位2配置", "灯牌", txtdp2.Text.Trim());
            objini.Writue("工位3配置", "灯牌", txtdp3.Text.Trim());
            objini.Writue("工位4配置", "灯牌", txtdp4.Text.Trim());
            objini.Writue("工位5配置", "灯牌", txtdp5.Text.Trim());
            objini.Writue("工位6配置", "灯牌", txtdp6.Text.Trim());

            objini.Writue("工位1配置", "灯牌厂家", LED_company_1.Text.Trim());
            objini.Writue("工位2配置", "灯牌厂家", LED_company_2.Text.Trim());
            objini.Writue("工位3配置", "灯牌厂家", LED_company_3.Text.Trim());
            objini.Writue("工位4配置", "灯牌厂家", LED_company_4.Text.Trim());
            objini.Writue("工位5配置", "灯牌厂家", LED_company_5.Text.Trim());
            objini.Writue("工位6配置", "灯牌厂家", LED_company_6.Text.Trim());

            objini.Writue("工位1配置", "屏号", cbbph1.Text.Trim());
            objini.Writue("工位2配置", "屏号", cbbph2.Text.Trim());
            objini.Writue("工位3配置", "屏号", cbbph3.Text.Trim());
            objini.Writue("工位4配置", "屏号", cbbph4.Text.Trim());
            objini.Writue("工位5配置", "屏号", cbbph5.Text.Trim());
            objini.Writue("工位6配置", "屏号", cbbph6.Text.Trim());


            objini.Writue("工位1配置", "工位名称", textBox_name1.Text.Trim());
            objini.Writue("工位2配置", "工位名称", textBox_name2.Text.Trim());
            objini.Writue("工位3配置", "工位名称", textBox_name3.Text.Trim());
            objini.Writue("工位4配置", "工位名称", textBox_name4.Text.Trim());
            objini.Writue("工位5配置", "工位名称", textBox_name5.Text.Trim());
            objini.Writue("工位6配置", "工位名称", textBox_name6.Text.Trim());

            objini.Writue("工位1配置", "启用", checkBox1.Checked ? "1" : "0");
            objini.Writue("工位2配置", "启用", checkBox2.Checked ? "1" : "0");
            objini.Writue("工位3配置", "启用", checkBox3.Checked ? "1" : "0");
            objini.Writue("工位4配置", "启用", checkBox4.Checked ? "1" : "0");
            objini.Writue("工位5配置", "启用", checkBox5.Checked ? "1" : "0");
            objini.Writue("工位6配置", "启用", checkBox6.Checked ? "1" : "0");

            objini.Writue("工位配置", "通讯", textBox1.Text.Trim());

            sbpz(objini, "工位1配置", listView2);
            sbpz(objini, "工位2配置", listView3);
            sbpz(objini, "工位3配置", listView4);
            sbpz(objini, "工位4配置", listView5);
            sbpz(objini, "工位5配置", listView6);
            sbpz(objini, "工位6配置", listView7);

            //objini.Writue("工位配置", "联网平台", comboBox1.Text.Trim());
            //objini.Writue("工位配置", "是否联网", comboBox2.Text.Trim());
            objini.Writue("工位配置", "检测线", comboBox3.Text.Trim());
            objini.Writue("工位配置", "抓拍IP地址", textBox2.Text.Trim());
            objini.Writue("工位配置", "抓拍端口", textBox3.Text.Trim());
            objini.Writue("工位配置", "检测时间是否达标", comboBox4.Text.Trim());

            objini.Writue("尾气配置", "灯牌", txtwqdp.Text.Trim());
            objini.Writue("尾气配置", "灯牌厂家", LED_company_wq.Text.Trim());

            objini.Writue("工位配置", "动态使用工位机控制", chedongtai.Checked?"是":"否");
            objini.Writue("工位配置", "启用多地沟", cheddg.Checked ? "是" : "否");
            objini.Writue("工位配置", "联网平台", textBox4.Text);

            基类窗体.UploadAndDownload fupload = new 基类窗体.UploadAndDownload();
            objini.Ini(System.Windows.Forms.Application.StartupPath + "\\系统信息.ini");
            string sjcxname = objini.ReadValue("系统信息", "检测线名称");
            string sgongweiname = objini.ReadValue("系统信息", "检测工位名称");
            fupload.upload(sjcxname, sgongweiname, "工位配置.ini");
        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
            工位配置.仪表配置 f = new 工位配置.仪表配置();
            string sgongwei = "";
            if (checkBox1.Checked) sgongwei += getgongwei(listView2);
            if (checkBox2.Checked) sgongwei += getgongwei(listView3);
            if (checkBox3.Checked) sgongwei += getgongwei(listView4);
            if (checkBox4.Checked) sgongwei += getgongwei(listView5);
            if (checkBox5.Checked) sgongwei += getgongwei(listView6);
            if (checkBox6.Checked) sgongwei += getgongwei(listView7);
            string[] ssz = sgongwei.Split(',');
            for (int i = 0; i < ssz.Length; i++)
            {
                if (ssz[i] == "地沟")
                    f.bAP = true;
                if (ssz[i] == "制动")
                    f.bBR = true;
                if (ssz[i] == "平板")
                    f.bFL = true;
                if (ssz[i] == "轮重")
                    f.bWE = true;
                if (ssz[i] == "灯光")
                    f.bLI = true;
                if (ssz[i] == "侧滑")
                    f.bSL = true;
                if (ssz[i] == "车速")
                    f.bSP = true;
                if (ssz[i] == "悬架")
                    f.bSU = false;
                if (ssz[i] == "动力性")
                    f.bDLX = true;
                if (ssz[i] == "经济性")
                    f.bYH = true;
                if (ssz[i] == "整备质量" || ssz[i] == "外廓尺寸")
                    f.bzbzl = true;
            }
            if (cheddg.Checked)
                f.bAPs = true;
            f.ShowDialog();
        }
        public string getgongwei(ListView lv)
        {
            string sreturn = "";
            foreach (ListViewItem li in lv.Items)
            {
                sreturn += li.SubItems[0].Text.Trim() + ",";
            }
            return sreturn;
        }

        private void LED_company_2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void gwpz_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F8)
            {
                label12.Visible = true;
                textBox4.Visible = true;
            }
        }
    }
}
